Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[spin]: Rework trigger docs #1450

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ThorstenHans
Copy link
Contributor

This PR is a rework of trigger related Spin documentation.

Once all triggers are documented, users will

  • be able to spot all different triggers
  • get instructions for installing them
  • see basic samples and fundamental app configuration

Sub Tasks

Merge once completed

  • HTTP trigger
  • Redis trigger
  • Command trigger
  • Cron trigger
  • SQS trigger
  • Kinesis trigger
  • MQTT trigger

Content must go through a pre-merge checklist.

Pre-Merge Content Checklist

This documentation has been checked to ensure that:

  • The title, template, and date are all set
  • Does this PR have a new menu item (anywhere in templates/*.hbs files) that points to a document .md that is set to publish in the future? If so please only publish the .md and .hbs changes in real-time (otherwise there will be a menu item pointing to a .md file that does not exist)
  • File does not use CRLF, but uses plain LF (hint: use cat -ve <filename> | grep $'\r' | wc -l and expect 0 as a result)
  • Has passed bart check
  • Has been manually tested by running in Spin/Bartholomew (hint: use PREVIEW_MODE=1 and run npm run styles to update styling)
  • Headings are using Title Case
  • Code blocks have the programming language set to properly highlight syntax and the proper copy directive
  • Have tested with npm run test and resolved all errors
  • Relates to an existing (potentially outdated) blog article? If so please add URL in blog to point to this content.

Signed-off-by: Thorsten Hans <[email protected]>
@ThorstenHans ThorstenHans marked this pull request as draft January 9, 2025 16:24

You can leverage different triggers as part of your Spin apps to address common requirements and build real-world, distributed applications with Spin.

### Common Triggers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what distinguishes a "common" trigger from a "community" one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought separation would make sense. Although mqtt is mostly written by fermyon ppl, its not under the fermyon org.

If we don't care, we could roll with just a single (simple) list of all triggers

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we just need to rephrase "common" to align more with "Fermyon"? It currently sounds like it contrasts with "rare" which is clearly not your intent!


You can leverage different triggers as part of your Spin apps to address common requirements and build real-world, distributed applications with Spin.

### Common Triggers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wary of repeating this list on every trigger page. Could we maybe instead have a "See all Spin triggers" link to a top level page? Or nerd snip Karthik into giving us some kind of 'include from file' feature?

content/spin/v3/command-trigger.md Outdated Show resolved Hide resolved

### Building and Running the Application

We can immediately run this pre-written (template) application and observe the time-driven execution:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time-driven? Possible copypasta from cron?

<iframe width="560" height="315" src="https://www.youtube.com/embed/l2nh_xpjCiM?si=fBPaiqoIkJPQ95W_" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

If you would like to learn more about using the Spin Command Trigger, please check out the [Spin Command Trigger GitHub repository](https://github.com/fermyon/spin-trigger-command/).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to include a troubleshooting/gotchas section to cover how this doesn't play nice with multi-trigger applications?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the command trigger that is definitely super important and useful. Will add a corresponding paragraph

With the plugin and template installed, we create a new application:

```bash
spin new -t cron-rust hello_cron --accept-defaults
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about --accept-defaults here - people presumably care about the actual execution schedule, so showing they get a chance to enter it might be good.


### Building and Running the Application

We can immediately run this pre-written (template) application and observe the time-driven execution:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am uncomfortable with "pre-written." "Template" or "starter" or "generated", but it's not really "pre-written".

cd hello_cron
spin build --up

Building component hello-cron with `cargo build --target wasm32-wasi --release`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should bump this to wasm32-wasip1 at some point (not a blocker here though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely, however all our templates are still using wasm32-wasi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/all/some\ of

content/spin/v3/triggers.md Outdated Show resolved Hide resolved
@@ -111,6 +111,26 @@
{{/if}} href="{{site.info.base_url}}/spin/v3/redis-trigger">The Redis
Trigger</a>
</li>
<li><a {{#if (active_project request.spin-full-url "/spin/v3/command-trigger" )}} class="active"
{{/if}} href="{{site.info.base_url}}/spin/v3/command-trigger">The Command
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you reckon is a good way to order the TOC here? The current scheme seems to be:

  • built ins, in order of importance
  • Fermyon-authored, in alphabetical? order
  • non-Fermyon-authored, unordered

This kind of requires users to know the provenance of their trigger in order to find it, which feels awkward.

On the other hand, strict alphabetical would make HTTP disappear into the middle of the list, which doesn't feel like it well serves the most common user needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can simple add "Available triggers" to the sidebar, and link to that page from each trigger instead of listing all there... feels smarter

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like that, it that would also give us a nice landing page for inbound links (and a place to explain the different statuses of the different triggers)

ThorstenHans and others added 3 commits January 9, 2025 22:06
Co-authored-by: itowlson <[email protected]>
Signed-off-by: Thorsten Hans <[email protected]>
Co-authored-by: itowlson <[email protected]>
Signed-off-by: Thorsten Hans <[email protected]>
Co-authored-by: itowlson <[email protected]>
Signed-off-by: Thorsten Hans <[email protected]>

> Please note: You can not `spin deploy` an application to Fermyon Cloud if it uses `kinesis` because non-HTTP triggers are not supported in Fermyon Cloud.

Let's look at how the [experimental Kinesis trigger for Spin](https://github.com/ogghead/spin-trigger-kinesis) allows you to deploy an application that runs based on real time data records streamed through AWS Kinesis. (Provisioning and configuring AWS Kinesis is out of scope for this article). The Kinesis trigger leverages AWS credentials from the standard AWS configuration environment variables and maps a AWS Kinesis stream to a specific component. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could clarify this by saying something like "parses data records streamed through AWS Kinesis with customizable processing delay" -- but I wonder if it gets into the weeds a bit too much.

... DATA: { "value" : "bar" }
```

As we can see from the above output, our application is now running and executing the function for each data record sent through your individual AWS Kinesis instance.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good callout @itowlson, agreed it might be worth rewording to clarify that function execution is per batch of records


> Please note: You can not `spin deploy` an application to Fermyon Cloud if it uses `kinesis` because non-HTTP triggers are not supported in Fermyon Cloud.

Let's look at how the [experimental Kinesis trigger for Spin](https://github.com/ogghead/spin-trigger-kinesis) allows you to deploy an application that runs based on real time data records streamed through AWS Kinesis. (Provisioning and configuring AWS Kinesis is out of scope for this article). The Kinesis trigger leverages AWS credentials from the standard AWS configuration environment variables and maps a AWS Kinesis stream to a specific component. For example:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing that an existing Kinesis stream and IAM credentials with permissions to read from it are prerequisites has benefit to readers if they are unfamiliar with AWS/are not ready to set those up. But it does also get into the weeds a bit.

Perhaps this information could live in a "prerequisites" subsection under "Installing the AWS Kinesis Trigger" before the sections on plugin installation/Spin configuration? Flexible on approach overall!

Unrelated, but it is potentially worth linking this AWS doc on credentials on "leverages AWS credentials from the standard AWS configuration environment variables" to help folks familiarize themselves with AWS credentials options.

```bash
spin plugins install --url https://github.com/fermyon/spin-trigger-cron/releases/download/canary/trigger-cron.json
```
### Common Triggers
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, i see the categorization slightly differently, partially because i feel "common" is a little vague.

  1. Triggers built into the spin CLI (http and redis)
  2. Triggers maintained by Spin (command, cron, sqs, mqtt)
  3. Community triggers (kinesis)

I bubbled MQTT into spin because it is a part of spinkube but i see how that could be seen as a community trigger too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants